local skel = fk.CreateSkill {
  name = "rmt__qiejun",
}

Fk:loadTranslationTable{
  ["rmt__qiejun"] = "窃钧",
  [":rmt__qiejun"] = "你造成伤害后，可以交出任意张牌，若含最后一张，回复1点体力；你受到伤害后，可以弃置任意张牌，若含最后一张，摸牌至体力上限。",

  ["#rmt__qiejun-give"] = "窃钧：可以交出任意张牌，若含最后一张，回复1点体力",
  ["#rmt__qiejun-discard"] = "窃钧：可以弃置任意张牌，若含最后一张，摸牌至体力上限",
}

skel:addEffect(fk.Damage, {
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and player == target and not player:isNude()
  end,
  on_cost = function (self, event, target, player, data)
    local targets = player.room:getOtherPlayers(player, false)
    -- 只能交给一名角色
    local tos, cards = player.room:askToChooseCardsAndPlayers(player, {
      targets = targets, max_num = 1, min_num = 1, max_card_num = 9999, min_card_num = 1, skill_name = skel.name,
      pattern = ".", cancelable = true, prompt = "#rmt__qiejun-give",
    })
    if #tos == 1 and #cards > 0 then
      event:setCostData(self, {tos = tos, cards = cards})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local cards = event:getCostData(self).cards
    local to = event:getCostData(self).tos[1]
    local all = #player:getCardIds("he") == #cards
    player.room:moveCardTo(cards, Card.PlayerHand, to, fk.ReasonGive, skel.name, nil, false, player)
    if player:isAlive() and player:isWounded() and all then
      player.room:recover{
        who = player,
        num = 1,
        recoverBy = player,
        skillName = skel.name,
      }
    end
  end
})

skel:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and player == target and not player:isNude()
  end,
  on_cost = function (self, event, target, player, data)
    local cards = player.room:askToDiscard(player, {
      min_num = 1, max_num = 999, cancelable = true, include_equip = true, skill_name = skel.name, skip = true,
      prompt = "#rmt__qiejun-discard",
    })
    if #cards > 0 then
      event:setCostData(self, {cards = cards} )
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local cards = event:getCostData(self).cards
    local draw = #player:getCardIds("he") == #cards
    player.room:throwCard(cards, skel.name, player, player)
    if player:isAlive() and draw and player:getHandcardNum() < player.maxHp then
      player:drawCards(player.maxHp - player:getHandcardNum(), skel.name)
    end
  end
})


return skel
